package Sockets;
import java.io.EOFException;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class TcpClient {

	public String request;

	public String getRequest() {
		return request;
	}

	public String sendRequest(String dados) {
		// arguments supply message and hostname
		Socket s = null;
		try {
			int serverPort = 7896;
			s = new Socket("localhost", serverPort);

			TcpServer server = new TcpServer();
			server.sendResquest(dados);

			return request = server.getRequest();

		} catch (UnknownHostException e) {
			System.out.println("Socket:" + e.getMessage());
		} catch (EOFException e) {
			System.out.println("EOF:" + e.getMessage());
		} catch (IOException e) {
			System.out.println("readline:" + e.getMessage());
		} finally {
			if (s != null)
				try {
					s.close();
				} catch (IOException e) {
					System.out.println("close:" + e.getMessage());
				}
		}

		return null;

	}
}
